function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

$(function(){
    $(".merchant_left a").click(function(){
        var classify_id=$(this).attr('data-aid')
        var merchant_id=$(this).attr('data-mid')
        var params={
            "classify_id":classify_id,
            "merchant_id":merchant_id
        }
        $.ajax({
            url:"/web_merchant/show",
            type: "post",
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            data: JSON.stringify(params),
            success: function (resp) {
                if (resp) {

                    // 先清空原有数据
                    $(".merchant_right ul").html('')
        
                    // 显示数据
                    for (var i=0;i<resp.commodity.length;i++) {
                        var commodity = resp.commodity[i]
                        var content = '<a href="/commodity_detail/'+ commodity.commodity_id + '">'
                        content +=' <li> <img src="'+ commodity.commodity_url + '" alt=""> <div> <p>'+ commodity.commodity_name +' </p> <p>单价：￥'+commodity.unit_price+' </p> <p>收藏数：'+commodity.collects+'</p> <h3>详情&rsaquo;</h3> </div> </li>'
                        content += ' </a>'
                        $(".merchant_right ul").append(content);
        
                    }
                }else{
                    // 请求失败
                    alert(resp.errmsg);
                }
            }
        })
    })
})